// <copyright file="CmsPage.cs" company="Clever Software">
// Copyright (c) 2013, 2014 All Right Reserved, http://www.cleversoftware.by
//
// This source is subject to the Microsoft Permissive License.
// Please see the License.txt file for more information.
// All other rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY 
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
//
// </copyright>
// <author>Clever Software</author>
// <email>info@cleversoftware.by</email>
// <date>2014-02-04</date> 
// <summary>CleverCMS source code</summary>

//All propertiex should be virtual according http://msdn.microsoft.com/en-us/library/dd468057.aspx

namespace CleverCMS.Cms.Data.Entities
{
    using System;
    using System.Collections.Generic;
    using System.Web.Mvc;
    using System.ComponentModel.DataAnnotations.Schema;
    using System.ComponentModel.DataAnnotations;

    public class CmsPage : CmsObject
    {
        public CmsPage()
        {
            this.Status = new DraftStatus();
            this. StatusId = 1;
        }
        /// <summary>
        /// 
        /// </summary>
        public virtual int StatusId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual int? CategoryId { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual int? AuthorId { get; set; }
      
        /// <summary>
        /// 
        /// </summary>
        public virtual string SeoTitle { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [Required(ErrorMessage = "Enter post title")]
        public virtual string PageTitle { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual string Alias { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual string PageContent { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual DateTime ModifiedAt { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual string MetaDescription { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual string MetaKeywords { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual bool HasComments { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual bool? Indexed { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual bool ShowRating { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual int ViewCount { get; set; }

        /// <summary>
        /// 
        /// </summary>
        [ForeignKey("AuthorId")]
        public virtual UserProfile Author { get; set; }
        /// <summary>
        /// 
        /// </summary>
        [NotMapped]
        public virtual CmsStatus Status { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual ICollection<CmsTag> Tags { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public virtual ICollection<CmsPageComment> PageComments { get; set; }

        #region Extensions
        [NotMapped]
        public ValueProviderResult TagString { get; set; }

        public static string CreateAlias(string title)
        {
            return title.ToString().ToLower().Trim().Replace(" ", "-");
        }

        public string GetUrl()
        {
            return this.Alias + "/";
        }
        #endregion
    }
}